package com.solarStruggle.controls

import java.awt.{Color, Font}
import scala.swing.{Alignment, Button, Component, Dialog, Frame, Label, ListView, ScrollPane}
import javax.swing.border.{EmptyBorder, LineBorder}
import scala.swing.event.{ButtonClicked, WindowDeactivated}
import domain.Vehicle

class FleetBuilder
extends MigPanel {

	val designs = new ListView[Vehicle] {
		renderer = new ListView.Renderer[Vehicle] {
			override def componentFor(list: ListView[_], isSelected: Boolean, hasFocus: Boolean, a: Vehicle, index: Int): Component = {
				val highlight = isSelected || hasFocus
				new Label {
					/*font = Fonts.sansation.deriveFont(Font.PLAIN, 14f) 
					foreground = new Color(24, 24, 24)
					opaque = true
					background = if(highlight) new Color(192, 192, 255) else new Color(255, 255, 255)
					border = if(highlight) new LineBorder(new Color(192, 192, 192)) else new EmptyBorder(5, 5, 5, 5)*/
					horizontalTextPosition = Alignment.Left
					verticalTextPosition = Alignment.Center
					text = a.name
				}
			}
		}
	}

	add(new Label("Designs"), "spanx 2, wrap")

	add(new ScrollPane(designs), "pushy, growy, spanx 2, wrap")

	add(new Button("Delete"))
	add(new Button("New...") {
		reactions += {
			case ButtonClicked(_) => {
				val frm = new VehicleCreator {
					reactions += {
						case WindowDeactivated(_) =>
							if(result == Dialog.Result.Ok) {
								designs.listData ++= List(vehicle)
							}
					}
				}
				frm.visible = true
			}
		}
	})

}
